
//前端拦截请求
// http request 拦截器
axios.interceptors.request.use(
    config => {
        //config相当于所有请求
        //取得token
        let token=localStorage.getItem("TOKEN")
        if(token){//不为空设置到请求头上
            config.headers["U-TOKEN"]=token;
        }
        return config
    },
    err => {
        return Promise.reject(err)
    })

// http response 拦截器
axios.interceptors.response.use(
    response => {
        console.log(response);
        //拦截响应，做统一处理
        if(!response.data.success&&response.data.message==="noAuth"){//拦截
            location.href="login.html"
            return ;//直接结束ser
        }
        return response
    },
    //接口错误状态处理，也就是说无响应时的处理
    error => {
        return Promise.reject(error.response.status) // 返回接口返回的错误信息
    })
//获取URL
function getUrlData(){
    var  url = location.search;  //获取url中"?"符后的字串
    var  theRequest =  new  Object();
    if  (url.indexOf( "?" ) != -1) {
        var  str = url.substr(1);
        strs = str.split( "&" );
        for ( var  i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split( "=" )[0]]=(strs[i].split( "=" )[1]);
        }
    }
    return  theRequest;
}
